//
//  CLShareManager.m
//  LoginShare
//
//  Created by Yiwi on 17/1/20.
//  Copyright © 2017年 Yiwi. All rights reserved.
//

#import "LLShareManager.h"
#import "LLShareManager+ShareView.h"
#import <UMSocialWechatHandler.h>
#import <UMSocialCore/UMSocialCore.h>
#import <UMSocialWechatHandler.h>
#import <UMSocialQQHandler.h>
#import <UMSocialSinaHandler.h>

@interface LLShareManager (){
    UIViewController *_shareVC;
    NSString *_content;
    UIImage *_image;
    NSString *_url;
}
@end

@implementation LLShareManager
+ (void)setShareAppKey{
    /* 打开调试日志 */
    [[UMSocialManager defaultManager] openLog:YES];
    /* 设置友盟appkey */
    [[UMSocialManager defaultManager] setUmSocialAppkey:@"58a1522e6e27a45f0d000e31"];
    /* 设置微信 */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx57d6beed38985919" appSecret:@"7997feda3a1e021ef1e23a863db38d8e" redirectURL:@"http://mobile.umeng.com/social"];
    /*设置QQ平台*/
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:@"1105918449"  appSecret:@"XNkhNdMaRyo6a3EH" redirectURL:@"http://mobile.umeng.com/social"];
    /* 设置新浪的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"wb3636021891"  appSecret:@"1d42ba9a5f617a8406ed01b1c742710d" redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
}



- (instancetype)init{
    self = [super init];
    if (self) {
        [self creatShareView];
    }
    return self;
}


- (void)show{
    self.shareBgView.hidden = NO;
    [UIView animateWithDuration:0.3 animations:^{
        self.shareBgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
        self.shareView.frame = CGRectMake(0, kScreenFrameH - 140, kScreenFrameW, 140);
    } completion:^(BOOL finished) {
        
    }];
}


- (void)hiddenShareView{
    [UIView animateWithDuration:0.3 animations:^{
        self.shareBgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
        self.shareView.frame = CGRectMake(0, kScreenFrameH, kScreenFrameW, 140);
    } completion:^(BOOL finished) {
        self.shareBgView.hidden = YES;
    }];
}

- (void)shareAction:(UIButton *)sender{
    [self hiddenShareView];

    if (sender.tag == 0) {
        [self shareWebPageToPlatformType:UMSocialPlatformType_QQ];
    }else if (sender.tag == 1) {
        [self shareWebPageToPlatformType:UMSocialPlatformType_WechatSession];
    }else if (sender.tag == 2) {
        [self shareWebPageToPlatformType:UMSocialPlatformType_WechatTimeLine];
    }else if (sender.tag == 3){
        [self shareWebPageToPlatformType:  UMSocialPlatformType_Sina];
    }
}


- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    
    //创建网页内容对象
    NSString* thumbURL =  @"https://mobile.umeng.com/images/pic/home/social/img-1.png";
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"平安测试" descr:@"胖子死胖啊没有未来！" thumImage:thumbURL];
    //设置网页地址
    shareObject.webpageUrl = @"http://www.baidu.com";
    
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************Share fail with error %@*********",error);
        }else{
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                
            }else{
                UMSocialLogInfo(@"response data is %@",data);
            }
        }
        //[self alertWithError:error];
    }];
}



@end
